/*
 * Ayuda.java
 *
 * Created on 27 de abril de 2006, 12:30 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package edu.unl.asd.vista.ayuda;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.WindowAdapter;
import java.net.URL;
import javax.help.HelpBroker;
import javax.help.HelpSet;
import javax.help.JHelp;
import javax.swing.JDialog;
import javax.swing.JPanel;

/**
 * 
 */
public class Ayuda {

    private HelpBroker help_browser = null;
    private HelpSet helpset = null;
    private HelpSet.Presentation hsp = null;
    JDialog frame = new JDialog();

    public Ayuda() {

        try {
            URL hsURL = this.getClass().getResource("/archivoAyuda/help_set.hs");
            helpset = new HelpSet(null, hsURL);

            JHelp help = new JHelp(helpset);

            JPanel panel = new JPanel(new GridLayout());
            panel.add(help);
            frame.setContentPane(panel);
            help.setNavigatorDisplayed(true);
            frame.setTitle("AYUDA");
            frame.setPreferredSize(new Dimension(1000, 600));
            frame.pack();
            frame.setLocationRelativeTo(null);
            
            frame.setVisible(true);
            frame.setResizable(false);
            frame.addWindowListener(new WindowAdapter() {            
                @Override
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    frame.dispose();                 
                }
            });
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    /** Creates a new instance of Ayuda */
    public Ayuda(Component component) {
        try {
            URL hsURL = this.getClass().getResource("/archivoAyuda/help_set.hs");
            helpset = new HelpSet(null, hsURL);
            hsp = helpset.getPresentation("HOLA");
            help_browser = helpset.createHelpBroker();
            help_browser.setHelpSetPresentation(hsp);
            help_browser.enableHelpOnButton(component, "ventana_principal", helpset);
            help_browser.enableHelpOnButton(component, "manual", helpset);
            help_browser.enableHelpOnButton(component, "ventana_secundaria", helpset);

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void showAyuda(String tema) {
        try {
            help_browser.setCurrentID(tema);
        } catch (Exception e) {
            help_browser.setCurrentID("INFORMACION");
        }
        help_browser.setDisplayed(true);
    }

    public static void main(String args[]) {
        new Ayuda();
    }
}
